package com.dsx.haha.servicempl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsx.haha.mapper.ArticleMapper;
import com.dsx.haha.model.entity.Article;
import com.dsx.haha.model.vo.ArticleVo;
import com.dsx.haha.service.ArticleService;
import com.dsx.haha.utils.RedPrint;
import com.dsx.haha.utils.UuidUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import java.util.Date;

/**
 * @author dsx
 * @date 2021/3/15 9:09
 * @since JDK1.8
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Autowired
    ArticleMapper articleMapper;
    @Bean
    public ArticleMapper setArticleMapper(){
        return articleMapper;
    }
    @Override
    public int addArticle(ArticleVo articleVo) {
        Article article = new Article();
        article.setId(UuidUtils.getUuid());
        article.setCreateDate(new Date());
        article.setArticleName(articleVo.getArticleName());
        article.setTenantId(articleVo.getTenantId());
        article.setCreateUserId(articleVo.getCreateUserId());
        RedPrint.print("ArticleServiceImpl-->addArticle-->article:"+article);
        return articleMapper.addArticle(article) ;
        
    }

    @Override
    public int removeArticle(ArticleVo articleVo) {
        return articleMapper.removeArticleBy(articleVo.getId());
    }
}
